package com.example.flowermall.controller;

import com.example.flowermall.entity.Orders;
import com.example.flowermall.entity.Result;
import com.example.flowermall.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dataTotal")
public class DataController {
    @Autowired
    IOrderService orderService;
    @GetMapping("/revenue")
    public Result revenue(){
        List<Orders> orders = orderService.selectRevenueT();
        List<Orders> ordersUnpaid = orderService.selectUnpaidT();
        List<Orders> ordersY = orderService.selectRevenueY();
        List<Orders> ordersUnpaidY = orderService.selectUnpaidY();
        int totalRevenue=0;
        int count=orders.size();
        int unpaidCount=ordersUnpaid.size();
        int order=count+unpaidCount;
        for(Orders orders1:orders){
            totalRevenue += orders1.getTotalPrice().longValue();
        }
        int totalRevenueY=0;
        int countY=orders.size();
        int unpaidCountY=ordersUnpaidY.size();
        int orderY=countY+unpaidCountY;
        for(Orders orders1:ordersY){
            totalRevenueY += orders1.getTotalPrice().longValue();
        }
        Result result=Result.success();
        result.put("total",totalRevenue);
        result.put("count",count);
        result.put("unpaidCount",unpaidCount);
        result.put("order",order);
        result.put("totalY",totalRevenueY);
        result.put("countY",countY);
        result.put("unpaidCountY",unpaidCountY);
        result.put("orderY",orderY);
        return result;
    }


}
